package site.xuxingcan.xposedxiwang;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

/**
 * Created by xuxingcan on 2016/10/25.
 */
public class DialogHelper {
    public interface DialogCallBack {
        void onConfirm(DialogInterface dialog, String s);

        void onCancel(DialogInterface dialog);
    }

    public interface MenuDialogCallBack {
        void onItemOnClick(DialogInterface dialog, int which);
    }

    public static void showConfirmDialog(Context mContext, String title, String msg, final DialogCallBack callBack) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);  //先得到构造器
        builder.setTitle(title); //设置标题
        builder.setMessage(msg); //设置内容
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { //设置确定按钮
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callBack != null) {
                    callBack.onConfirm(dialog, null);
                }
            }
        });
        builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { //设置取消按钮
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callBack != null) {
                    callBack.onCancel(dialog);
                }
            }
        });
        builder.setCancelable(false);
        builder.create().show();
    }

    public static void showMessageDialog(Context mContext, String msg) {
        showMessageDialog(mContext, "信息", msg, null);
    }

    public static AlertDialog showOnlyMessageDialog(Context mContext, String title, String msg) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);  //先得到构造器
        builder.setTitle(title); //设置标题
        builder.setMessage(msg); //设置内容
        builder.setCancelable(false);
        AlertDialog dialog = builder.create();
        dialog.show();
        return dialog;
    }

    public static void showMessageDialog(Context mContext, String title, String msg, final DialogCallBack callBack) {
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);  //先得到构造器
        builder.setTitle(title); //设置标题
        builder.setMessage(msg); //设置内容
        builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { //设置确定按钮
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (callBack == null) {
                    dialog.dismiss();
                } else {
                    callBack.onConfirm(dialog, null);
                }
            }
        });
        builder.setCancelable(false);
        builder.create().show();
    }
}
